const promisify = mpFunction => options =>
  new Promise((resolve, reject) =>
    mpFunction({
      ...options,
      success: resolve,
      fail: err => reject(new Error(err.errMsg))
    }))
const keyDataPromisify = mpFunction => (key, data) =>
    promisify(mpFunction)({ key, data })
  
const wxApis = {};

[
    'setStorage',
    'getStorage',
    'removeStorage',
].forEach((name) => {
    wxApis[name] = keyDataPromisify(wx[name]);
});

[
    'checkSession',
    'clearStorage',
    'login',
    'request',
    'getUserInfo',
].forEach((name) => {
    wxApis[name] = promisify(wx[name]);
});

export default wxApis;
